/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Facebook;

import charts.Connexion;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.sql.SQLException;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrateur
 */
public class Sharingimages extends javax.swing.JFrame {

    /**
     * Creates new form Sharingimages
   */
    public Sharingimages() {
        initComponents();
         setResizable(false);
        setBounds(50, 50, 400, 219);
        getContentPane().setLayout(null);
       Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension windowSize = this.getSize();
        int windowX = Math.max(0, (screenSize.width  - windowSize.width ) / 2);
        int windowY = Math.max(0, (screenSize.height - windowSize.height) / 2)-20;
        this.setLocation(windowX, windowY);
         

    }  

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        path = new javax.swing.JTextField();
        browsbout = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jList1);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/fb.jpg"))); // NOI18N
        jButton1.setText("Share Image");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setText("video");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        setTitle("Partage Image");
        getContentPane().setLayout(null);
        getContentPane().add(path);
        path.setBounds(70, 110, 270, 30);

        browsbout.setText("Parcourir");
        browsbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browsboutActionPerformed(evt);
            }
        });
        getContentPane().add(browsbout);
        browsbout.setBounds(140, 70, 120, 30);
        getContentPane().add(jSeparator1);
        jSeparator1.setBounds(70, 40, 290, 20);

        jLabel2.setFont(new java.awt.Font("Lucida Calligraphy", 1, 18)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Selectionnez une image");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(90, 10, 280, 30);

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/app/gui/images/fbsh.jpg"))); // NOI18N
        jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel3MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel3MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabel3MouseExited(evt);
            }
        });
        getContentPane().add(jLabel3);
        jLabel3.setBounds(140, 160, 120, 30);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/app/gui/images/face.jpg"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, -80, 520, 360);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
 

    }//GEN-LAST:event_jButton1ActionPerformed

    private void browsboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browsboutActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.showOpenDialog(null);
        File f = chooser.getSelectedFile();
       filename = f.getAbsolutePath();

        path.setText(filename);
        try {
            File image = new File(filename);
            FileInputStream fis = new FileInputStream(image);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] buf = new byte[1024];
            for (int readNum; (readNum = fis.read(buf)) != -1;) {
                bos.write(buf, 0, readNum);

            }



        } catch (Exception e) {
        }
}//GEN-LAST:event_browsboutActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jLabel3MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel3MouseEntered
        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/app/gui/images/fbsh2.jpg")));
    }//GEN-LAST:event_jLabel3MouseEntered

    private void jLabel3MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel3MouseExited
        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/app/gui/images/fbsh.jpg")));
    }//GEN-LAST:event_jLabel3MouseExited

    private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel3MouseClicked
       String ch= filename;
 System.out.println(ch);
GraphPublisherExample g = new GraphPublisherExample("AAAIO62GqZA2ABAIbffeoyQ5mVXHZCHPiE4llcBUAXlrFZBVBlgZBhigDh924tZAWvTBFNZCMuOByZCZBHeDMZBoatCkZBynuLJKcxxvPCH4o8xywZDZD");
g.publishPhoto(ch);
JOptionPane.showMessageDialog(this, "Image partagé  !", "Share", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_jLabel3MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
      
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Sharingimages().setVisible(true);
               
            }
        });
    }
     String filename;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton browsbout;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField path;
    // End of variables declaration//GEN-END:variables
}
